using MediatR;
using MES.Server.API.Application.Command.ApprovalProcess;
using Microsoft.AspNetCore.Mvc;
using ReturnValue;
using System.Threading.Tasks;

namespace ERP.Server.API.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ApprovalFlowController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ApprovalFlowController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 保存审批流程设计
        /// </summary>
        /// <param name="command">流程设计信息</param>
        /// <returns>保存结果</returns>
        [HttpPost("saveDesign")]
        public async Task<ApiResult<bool>> SaveApprovalFlowDesign([FromBody] SaveApprovalFlowDesignCommand command)
        {
            return await _mediator.Send(command);
        }
        
        /// <summary>
        /// 获取审批流程设计
        /// </summary>
        /// <param name="businessId">业务ID（如采购单ID）</param>
        /// <param name="businessType">业务类型（如PurchaseOrder）</param>
        /// <returns>流程设计信息</returns>
        [HttpGet("getDesign")]
        public async Task<ApiResult<FlowDesignDTO>> GetApprovalFlowDesign([FromQuery] long businessId, [FromQuery] string businessType)
        {
            var command = new GetApprovalFlowDesignQuery
            {
                BusinessId = businessId,
                BusinessType = businessType
            };
            return await _mediator.Send(command);
        }
    }
}
